package net.sakz.oss;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class OSSWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
	@Value("${sso.login.url}")
	private String ssoLoginUrl;
	@Value("${sso.verfiy.url}")
	private String ssoVerfiyUrl;
	
	
	    //@Bean  
	    public FilterRegistrationBean filterRegist() {  
	        FilterRegistrationBean frBean = new FilterRegistrationBean();  
	        frBean.setFilter(new LoginOutFilter());  
	        frBean.addUrlPatterns("/*");
	        frBean.setEnabled(true);
	        frBean.addInitParameter("ssoLoginUrl", ssoLoginUrl);
	        frBean.addInitParameter("ssoVerfiyUrl", ssoVerfiyUrl);
	        frBean.setOrder(0);
	        return frBean;  
	    }
	    @Bean
	    public FilterRegistrationBean shiroFilter() {
	    	FilterRegistrationBean registrationBean = new FilterRegistrationBean();
	    	   DelegatingFilterProxy httpBasicFilter = new DelegatingFilterProxy();
	    	   registrationBean.setFilter(httpBasicFilter);
	    	   Map<String,String> m = new HashMap<String,String>();
	    	   m.put("targetBeanName","shiroFilter");
	    	   m.put("targetFilterLifecycle","true");
	    	   registrationBean.setInitParameters(m);
	    	   List<String> urlPatterns = new ArrayList<String>();
	    	   urlPatterns.add("/*");
	    	   registrationBean.setUrlPatterns(urlPatterns);
	    	   return registrationBean;
	    	
	    }
	        
	    

}
